import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/4/1 8:37
 */
class ListNode {
    int val;
    ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

public class Solution {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(0, head);
        ListNode fast = dummy, slow = dummy;

        //先让快指针移动n步
        for (int i = 0; i < n; i++) {
            fast = fast.next;
        }

        //双指针同时移动，直到fast移动到链表末尾
        while (fast.next != null) {
            fast = fast.next;
            slow = slow.next;
        }

        slow.next = slow.next.next;
        return dummy.next;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            ListNode head = null;
            ListNode tail = null;
            int len = in.nextInt();
            for (int i = 0; i < len; i++) {
                int val = in.nextInt();
                ListNode newNode = new ListNode(val);
                if (head == null) {
                    head = newNode;
                    tail = newNode;
                } else {
                    tail.next = newNode;
                    tail = newNode;
                }
            }
            int n = in.nextInt();
            Solution solution = new Solution();
            ListNode ret = solution.removeNthFromEnd(head, n);
            while (ret != null) {
                System.out.print(ret.val + " ");
                ret = ret.next;
            }
        }
    }
}